package serverHandling;

import jsonObjects.Attributes;
import jsonObjects.Files;
import jsonObjects.Profile;
import org.apache.http.cookie.Cookie;

import java.util.ArrayList;
import java.util.List;

public class SessionObjects {
    private static List<Profile> profiles;
    private static List<Cookie> cookies = new ArrayList<Cookie>();

    public static List<Cookie> getCookies() {
        return cookies;
    }

    public static void setCookies(List<Cookie> cookiesInc) {
        cookies = cookiesInc;
    }

    public static List<Profile> getProfiles() {
        return profiles;
    }

    public static void setProfiles(List<Profile> jsonObjInc) {
        profiles = jsonObjInc;
    }

    public static Profile getProfileByName(String profileName) {
        for (Profile p : profiles)
            if (p.getName().equals(profileName))
                return p;

        return null;
    }

    public static Attributes[] getProfileAttributes(String profileId) {
        for (Profile p : profiles)
            if (p.getId().equals(profileId))
                return p.getAttributes();

        return null;
    }

    public static void addFilesToProfile(String profileName, ArrayList<Files> files) {
        for (Profile p : SessionObjects.getProfiles())
            if (p.getName().equals(profileName))
                p.setFiles(files);
    }

    public static Files getFileFromProfile(String profileName, String fileName) {
        Profile tmp = null;
        for (Profile p : SessionObjects.getProfiles())
            if (p.getName().equals(profileName)) {
                tmp = p;
                continue;
            }

        if (tmp != null)
            for (Files f : tmp.getFiles())
                if (f.getName().equals(fileName)) return f;

        return null;
    }

}
